#include <iostream>
#include <algorithm>
#include <vector>

void print(const int &i)
{
    std::cout << i << " ";
}

int main(int argc, char const *argv[])
{
    int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int arr2[] = {2, 4, 6, 8, 10, 11};

    std::vector<int> v1 = {arr1, arr1 + (sizeof(arr1) / sizeof(int))};
    std::vector<int> v2 = {arr2, arr2 + (sizeof(arr2) / sizeof(int))};

    std::for_each(v1.begin(), v1.end(), print);
    std::cout << std::endl;
    std::for_each(v2.begin(), v2.end(), print);
    std::cout << std::endl;

    // 交集
    std::vector<int> v3{};
    v3.resize(std::min(v1.size(), v2.size()));
    std::vector<int>::iterator it1 = std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());

    std::for_each(v3.begin(), it1, print);
    std::cout << std::endl;

    // 并集
    std::vector<int> v4{};
    v4.resize(v1.size() + v2.size());
    std::vector<int>::iterator it2 = std::set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), v4.begin());
    std::for_each(v4.begin(), it2, print);
    std::cout << std::endl;

    // 差集
    // 差集 v2 对 v1 求差集

    std::vector<int> v5{};
    v5.resize(std::max(v1.size(), v2.size()));
    std::vector<int>::iterator it3 = std::set_difference(v2.begin(), v2.end(), v1.begin(), v1.end(), v5.begin());
    std::for_each(v5.begin(), it3, print);
    std::cout << std::endl;

    // 差集 v1 对 v2 求差集
    std::vector<int> v6{};
    v6.resize(std::max(v1.size(), v2.size()));
    std::vector<int>::iterator it4 = std::set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), v6.begin());
    std::for_each(v6.begin(), it4, print);
    std::cout << std::endl;

    return 0;
}
